package org.future.wsdl.data;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Vector;



/**
 * xml 数据类型映射表
 * @author dycc
 *
 */
public class BaseTypeTable {
    private static Map<String,String> simpleType2xsd = new HashMap<String,String>();
    private static Set<String> simpleType = new HashSet<String>();

    static {
        // primary type
        simpleType2xsd.put("byte","byte");
        simpleType2xsd.put("short","short");
        simpleType2xsd.put("int","int");
        simpleType2xsd.put("long","long");
        simpleType2xsd.put("float", "float");
        simpleType2xsd.put("double","double");
        simpleType2xsd.put("char","string");
        simpleType2xsd.put("boolean", "boolean");
        // boxing class type
        simpleType2xsd.put("java.lang.Byte","byte");
        simpleType2xsd.put("java.lang.Short", "short");
        simpleType2xsd.put("java.lang.Integer","int");
        simpleType2xsd.put("java.lang.Long","long");
        simpleType2xsd.put("java.lang.Float","float");
        simpleType2xsd.put("java.lang.Double","double");
        simpleType2xsd.put("java.lang.Character","anyType");
        simpleType2xsd.put("java.lang.Boolean","boolean");
        // string
        simpleType2xsd.put("java.lang.String","string");
        // util class type
        simpleType2xsd.put("java.util.Date","date");
        simpleType2xsd.put("java.util.Calendar","dateTime");
        // SQL date time
        simpleType2xsd.put("java.sql.Date","date");
        simpleType2xsd.put("java.sql.Time","time");
        simpleType2xsd.put("java.sql.Timestamp","dateTime");
        //consider BigDecimal, BigInteger, Day, Duration, Month, MonthDay,
        //Time, Year, YearMonth as SimpleType as well
        simpleType2xsd.put("java.math.BigDecimal","decimal");
        simpleType2xsd.put("java.math.BigInteger","integer");      
        // object
        simpleType2xsd.put("java.lang.Object","anyType");
        // Any types
        simpleType2xsd.put(ArrayList.class.getName(),"anyType");
        simpleType2xsd.put(Vector.class.getName(),"anyType");
        simpleType2xsd.put(List.class.getName(),"anyType");
        simpleType2xsd.put(HashMap.class.getName(),"anyType");
        simpleType2xsd.put(Hashtable.class.getName(),"anyType");
        //byteArrat
        simpleType2xsd.put("base64Binary","base64Binary");
        // init the simple type set
        simpleType = new HashSet<String>(simpleType2xsd.values());
    }
    /**
     * 是否为 xml 中的基本数据类型
     * @param type
     * @return
     */
    public static boolean isSimpleXmlType(String type){
        return simpleType.contains(type);
    }
}
